package de.ama.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;

/**
 * Created by IntelliJ IDEA.
 * User: x
 * Date: 20.02.11
 * Time: 21:42
 * To change this template use File | Settings | File Templates.
 */
public class CursorController {

  private final static MouseAdapter mouseSink = new MouseAdapter() {};

  private CursorController() {}

  /** Sets cursor for specified component to Wait cursor */
  public static void startWaitCursor(JComponent component) {
    RootPaneContainer root =
      ((RootPaneContainer) component.getTopLevelAncestor());
    root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    root.getGlassPane().addMouseListener(mouseSink);
    root.getGlassPane().setVisible(true);
  }

  /** Sets cursor for specified component to normal cursor */
  public static void stopWaitCursor(JComponent component) {
    RootPaneContainer root =
      ((RootPaneContainer) component.getTopLevelAncestor());
      root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    root.getGlassPane().removeMouseListener(mouseSink);
    root.getGlassPane().setVisible(false);
  }

}
